package com.zhu.cloud.service;

import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service
public class UserServiceImpl implements UserService {
    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {

//        UserDetails details = new User("root","root", Collections.singleton(new SimpleGrantedAuthority("ADMIN")));
        /**
         * 因为{@link com.zhu.cloud.config.WebSecurityConfigurer#passwordEncoder()}使用了BCryptPasswordEncoder加密,所以要用encoder处理一下密码
         */
        UserDetails details = new User("root",encoder.encode("root"), Collections.singleton(new SimpleGrantedAuthority("ADMIN")));
        return details;
    }
}
